app.controller("orderController",function($scope,$location,orderService,mycartService){
	$scope.loadDatas=function(){
		orderService.loadDatas($location.search().oid).then(function success(response){
			console.log(response);
			if(response.data.status==="success"){
				$scope.order=response.data.data;
			}
		});
	}
	$scope.deleteItemsById=function(pid,oid){
		orderService.deleteData(pid,oid).then(function success(response){
			console.log(response);
			if(response.data.flag){
				$scope.order=JSON.parse(response.data.message);
			}
		});
		
	}
	$scope.addAddress=function(uid){
		orderService.addAddress($scope.address,$scope.receciver,$scope.tel,uid).then(function success(response){
			console.log(response);
			if(response.data.status==="success"){
				location.href="mycart.html#?oid="+$location.search().oid;
			}
		});
		mycartService.addCart($location.search().oid).then(function success(response){
			console.log(response);
		    alert(response.data.data);
		});
	}
	$scope.check=function(pid,$event){
		orderService.modifyItemsQty(pid,$event.target.value,$location.search().oid).then(function success(response){
			console.log(response);
			$scope.flag=response.data.flag;
			if(response.data.flag){
				$scope.cars=JSON.parse(response.data.message);
			}
		});
	}
});